﻿using System.Collections.Generic;
using System.Windows.Media;
using System.Windows;

namespace SuperFrame.Charts
{
    public class ContainerColumn : SeriesContainer
    {
        public ContainerColumn() : base()
        {
        }

        public override void Draw()
        {
            base.Draw();
        }
        override protected void DrawPath(BaseSeries series, System.Drawing.Pen pen)
        {
            if (series is SeriesColumn)
            {
                var points = new PointCollection();
                var pointCount = 0;
                var rects = new List<Rect>();
                SeriesColumn SeriesColumn = series as SeriesColumn;
                points = SeriesColumn.ColumnPoints;
                pointCount = SeriesColumn.ColumnPoints.Count;
                rects = SeriesColumn.rects;
                System.Drawing.Brush fill = SeriesColumn.Fill.AsDrawingBrush();
                //System.Drawing.Pen fillPen = new System.Drawing.Pen(fill);
                if (RenderingMode == RenderingMode.Default)
                {
                    for (int i = 0; i < SeriesColumn.Parts.Count; i++)
                    {
                        System.Windows.Shapes.Rectangle element = (SeriesColumn.Parts[i] as PartColumn).CreatePart() as System.Windows.Shapes.Rectangle;
                        PartsCanvas.Children.Add(element);
                        System.Windows.Controls.TextBlock text = (SeriesColumn.Parts[i] as PartColumn).CreateTxt() as System.Windows.Controls.TextBlock;
                        PartsCanvas.Children.Add(text);
                    }
                }
                else
                {
                    for (int i = 0; i < rects.Count; i++)
                    {
                        Rect rect = rects[i];
                        switch (RenderingMode)
                        {
                            case RenderingMode.GDIRendering:
                                GDIGraphics.DrawRectangle(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
                                GDIGraphics.FillRectangle(fill, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
                                break;
                            case RenderingMode.Default:
                                break;
                            case RenderingMode.WritableBitmap:
                                this.WritableBitmap.Lock();
                                WritableBitmapGraphics.DrawRectangle(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
                                WritableBitmapGraphics.FillRectangle(fill, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
                                this.WritableBitmap.Unlock();
                                break;
                            default:
                                break;
                        }
                    }
                    this.collection.InvalidateBitmap();
                }
            }
        }

    }
}
